//new register js,start
var cls_success = "suc-icon";
var cls_msg_err = "msg-weak err-tips";
var cls_err = "err";
var cls_cur = "msg-weak";
var cls_base = "reg-items";
var cls_base_name = "reg-items items-1";
var cls_base_password = "reg-items items-2";
var cls_base_confirmPassword = "reg-items items-3";
var cls_base_authenticCode = cls_base;
var cls_base_verifyCode = cls_base;
var cls_focus = "focus";

var cls_base_mobileIllegal = "checkMobileTipError";//手机验证码错误时
var cls_base_emailIllegal = "checkEmailTipError";//邮箱验证码错误时
var cls_base_verifyCodeEmail = "verifyCodeEmailTips";
var verifyCodeEmailTips = "verifyCodeEmailTips";
var msg_authenticCodeFocus = "";

function handleCreate() {

    var verifyName = $("#" + ele_name).attr('verify');
    var verifyPassword = $("#" + ele_password).attr('verify');
    var verifyConfimPassword = $("#" + ele_confirmPassword).attr('verify');

    var verifyAuthenticCode = $("#" + ele_authenticCode).attr('verify');
    verifyAuthenticCode = $("#" + ele_authenticCode).length == 0 ? 'yes' : verifyAuthenticCode;

    var name = $("#" + ele_name).val();
    var mobile = $("#mobile").attr('verify'); //add by ywf 2015-11-10
    var email = $("#email").attr('verify');

    if (!verifyName || verifyName != 'yes') {
        $("#" + ele_name).blur();
        return;
    }

    if (!verifyPassword || verifyPassword != 'yes') {
        $("#" + ele_password).blur();
        return;
    }
    if (!verifyConfimPassword || verifyConfimPassword != 'yes') {
        $("#" + ele_confirmPassword).blur();
        return;
    }
    if (!checkMobileNumber($("#mobile").val()) && !checkEmail($("#email").val())) {
        alert("请先验证手机或邮箱");
        return;
    }
    var authenticCode = $.trim($("#authenticCode").val());
    if (isColseRegisterCaptcha != true && checkMobileNumber($("#mobile").val())) {
        //使用验证码
        if ((!verifyAuthenticCode || verifyAuthenticCode != 'yes') || authenticCode == "" || authenticCode == null) {
            $("#" + ele_authenticCode).blur();
            return;
        }
        var verifyCode = $("#verifyCode").val();
        if (verifyCode == "" || verifyCode.length != 6 || (!verifyCode.match('^[0-9]{1,}$'))) {
            $("#verifyCode").blur();
            return;
        }

    }
    if (isColseEmailRegister != true && isColseRegisterCaptchaEmail != true && checkEmail($("#email").val())) {
        //使用验证码
        if ((!verifyAuthenticCode || verifyAuthenticCode != 'yes') || authenticCode == "" || authenticCode == null) {
            $("#" + ele_authenticCode).blur();
            return;
        }
        var verifyCodeEmail = $("#verifyCodeEmail").val();
        if (verifyCodeEmail == "" || verifyCodeEmail.length != 6 || (!verifyCodeEmail.match('^[0-9]{1,}$'))) {
            $("#verifyCodeEmail").blur();
            return;
        }
    }
    //add by ywf 2015-12-22
    if ($("#mobile").attr('verify') != "yes" && $("#email").attr('verify') != "yes") {
        //非法提交
        return;
    }

    if (!$("#checkInput").prop("checked")) {
        $("#serviceAgreement").show();
        $("#serviceAgreement .rule-box-text").css("color", "#c00");
        return;
    }

    var options = {
        async: false,
        dataType: "json",
        success: function(data) {
            var name = $.trim($("#name").val());
            if (data && data.success) {
                if (checkMobileNumber(name)) {
                    data.regSuccessUrl += '?flag=m';
                }
                var redirectUrl = "";
                if (data.redirectUrl) {
                    redirectUrl = data.redirectUrl;
                } else {
                    redirectUrl = data.regSuccessUrl;
                }
                var pt = $("#pageType").val();
                if (pt && 'pop' == pt) {
                    redirectUrl = '';
                }
                notifyOthers(data.externalUrls, redirectUrl);
                if ($("#popOperationIframe") && $("#popOperationIframe").attr("src")) {
                    $("#popOperationIframe").attr("src", popOperationIframeSrc);
                }
            } else {
                var message = data.errorMessage;
                if (message.indexOf('login') >= 0) {
                    showNameTipsWhenExists(name, '');
                    $('#authenticCode').val('');
                    $('#codeRefreshControlCenter').click();
                } else if (message.split('|').length > 1) {
                    var eleName = message.split('|')[0];
                    var message = message.split('|')[1];
                    showErrorTips(message, eleName);
                    if (eleName != "system") {
                        alert(message);
                    }
                    if (message == "图片验证码错误") {
                        changeImageAuthenticCode('codeRefreshControlCenter');
                    }
                    $('#codeRefreshControlCenter').click();
                } else {
                    alert("注册失败，请稍后再试！");
                    $('#codeRefreshControlCenter').click();
                }
            }
        },
        error: function(XMLHttpRequest, textStatus, errorThrown) {
            alert('注册失败，请稍后再试！');
        }
    };
    //document.registerForm.submit();
    $("#registerForm").ajaxSubmit(options);

    omnitureForLink('立即注册');
}
var changedName = '';
function nameBlur() {
    $("#nameFocusbox").hide();
    if ($("#nameTips").html() != "") {
        $("#nameTips").show();
    }
    $("#nameSuc").show();
    //隐藏推荐邮箱层
    showNameList(false);
    //去除失去焦点class
    $("#name").removeClass(cls_focus);

//	$("#"+ele_name).attr('verify', 'false');
    //不需要去空格，空格算非法字符
    var name = $("#registerForm #name").val();
    //(b)
    if (!name) {
        showErrorTips(msg_nameNotEmpty, ele_name);
        $("#" + ele_name).attr('verify', 'false');
        return false;
    }
    if (name == '') {
        showErrorTips(msg_nameNotEmpty, ele_name);
        $("#" + ele_name).attr('verify', 'false');
        return false;
    }

    //mod by ywf 2015-12-23 允许汉字注册，以下两个判断有变化
    //add by ywf 2015-11-11 只需校验用户名的长度和复杂度
//	if($.trim(name).length < 6 || $.trim(name).length > 20) {
//		showErrorTips(msg_nameLength6To20, ele_name);
//		$("#nameSuc").hide();
//		return false;
//	}
//	var matchs = name.match('^[a-zA-Z0-9_-]+$');//^[^0-9]\\w+$
//	if(!matchs || matchs[0].length != name.length) {
//		showErrorTips(msg_nameInvalidCode, ele_name);
//		$("#nameSuc").hide();
//		return false;
//	}

    if (strlen(name) < 4 || strlen(name) > 20) {
        showErrorTips(msg_nameLength4To20, ele_name);
        $("#" + ele_name).attr('verify', 'false');
        $("#nameSuc").hide();
        return false;
    }
//	var matchs = name.match('^[a-zA-Z0-9_-]+$');//^[^0-9]\\w+$
//	if(!matchs || matchs[0].length != name.length) {
//		showErrorTips(msg_nameInvalidCode, ele_name);
//		$("#nameSuc").hide();
//		return false;
//	}
// add by ywf 2015-12-23 不再需要上面的判断，中文也可以注册了
    if (containSpecial(name)) {
        showErrorTips(msg_nameInvalidCode, ele_name);
        $("#" + ele_name).attr('verify', 'false');
        $("#nameSuc").hide();
        return false;
    }

    if (name.match('^[0-9]{1,}$')) {
        showErrorTips(msg_nameCanntAllNumber, ele_name);
        $("#" + ele_name).attr('verify', 'false');
        $("#nameSuc").hide();
        return false;
    }

    //$("#"+ele_name).attr('verify', 'yes');
    //相同用户名检查
    checkLoginUsable();
    return true;
}

function passwordBlur() {
    $("#capsLocked").hide();//失去焦点时，隐藏大写按键开启的提示
    var name = $("#name").val();
    var pass = $("#password").val();
    if (name == pass && name != "") {
        //alert("用户名和密码不能相同，请重新输入！");
        showErrorTips(mag_passwordSameUserName, ele_password);
        return;
    }
    if ($("#password").attr("isClick") == "false") {
        if ($("#tj_name").css("display") != "block") {
            $("#password").removeClass(cls_focus);
            var password = $("#registerForm #password").val();
            if (!checkPassword(password, true)) {
                $("#pwd-safe").hide();
                return false;
            }
            $("#passwordSuc").show();
            $("#pwd-safe").show();

            var confirmPassword = $.trim($("#" + ele_confirmPassword).val());
            if (confirmPassword) {
                $("#" + ele_confirmPassword).blur();
            }
        }
    }
}

function changePasswordGrade() {
    //initial
    $("#" + ele_password).attr('verify', 'false');
    $("#" + ele_confirmPassword).attr("disabled", true);
    $("#" + ele_confirmPassword).css('background-color', '#f3f3f3');
    if (this.value)
        $("#pwd-safe").show();

    var password = $("#registerForm #password").val();

    //初始化为弱
    $(".pw-safe").removeClass('pw-halfstrong');
    $(".pw-safe").removeClass('pw-medium');
    $(".pw-safe").removeClass('pw-weak');
    $(".pw-safe").removeClass('pw-none');
    $(".pw-safe").addClass('pw-weak');

    //(d)密码强度判断的规则
    var matchs1 = password.match('[~!@#$%^&*()_+\\-=]');
    var matchs2 = password.match('[A-Za-z]');
    var matchs3 = password.match('[0-9]');
    var x = 0;
    if (matchs1)
        x++;
    if (matchs2)
        x++;
    if (matchs3)
        x++;
    if (x == 3) {
        $(".pw-safe").attr('class', 'pw-safe pw-strong');
    } else if (x == 2) {
        $(".pw-safe").attr('class', 'pw-safe pw-medium');
    } else if (x == 1) {
        $(".pw-safe").attr('class', 'pw-safe pw-weak');
    } else {
        $(".pw-safe").attr('class', 'pw-safe pw-none');
    }

    if (!checkPassword(password, false))
        return false;

    //(e)
    showSuccessTips('', ele_password);
    //激活确认密码输入
    $("#confirmPassword").removeAttr("disabled");
    $("#" + ele_confirmPassword).css('background-color', '');
    $("#" + ele_password).attr('verify', 'yes');
    $("#" + ele_password + "Div").removeClass('cur');
    return true;
}

function confirmPasswordBlur() {
    $("#confirmPassword").removeClass(cls_focus);
    $("#" + ele_confirmPassword).attr('verify', 'false');
    var password = $("#registerForm #password").val();
    var confirmPassword = $("#registerForm #confirmPassword").val();

    if (!confirmPassword) {
        showErrorTips(msg_passwordNotEmpty, ele_confirmPassword);
        return false;
    }

    if (password != confirmPassword) {
        showErrorTips(msg_confirmPasswordNotSame, ele_confirmPassword);
        return false;
    }

    showSuccessTips('', ele_confirmPassword);
    $("#" + ele_confirmPassword).attr('verify', 'yes');
    $("#" + ele_confirmPassword + "Div").removeClass('cur');
    $("#" + ele_confirmPassword + "Suc").show();
    $("#" + ele_confirmPassword + "Tips").hide();
    return true;
}
function authenticCodeBlur() {
    if ($("#authenticCodeDiv").hasClass('hide')) {
        return;
    }
    $("#authenticCode").removeClass(cls_focus);
    var authenticCode = $.trim($("#authenticCode").val());
    $("#" + ele_authenticCode).attr('verify', 'false');
    //resetElement("authenticCode");
    if (!authenticCode) {
        showErrorTips(msg_authenticCodeNotEmpty, ele_authenticCode);
        return false;
    }
    if (authenticCode.length != 4) {
        showErrorTips(msg_authenticCodeError, ele_authenticCode);
        return false;
    }
    showNormalTips('', ele_authenticCode);
    $("#authenticCodeTips").hide();
    $("#" + ele_authenticCode).attr('verify', 'yes');
    return true;
}
function validateAuthenticCode(event) {
    if (event.keyCode == 13 || event.which == 13) {
        return;
    }
    $("#" + ele_authenticCode).attr('verify', 'false');
    var authenticCode = $.trim($("#authenticCode").val());
    if (authenticCode.length == 4) {
        var options = {
            async: false,
            data: {type: 'validate', code: authenticCode},
            url: storeSite + "/images/generatorCode.no",
            success: function(data) {
                var verifyFlag = $.trim(data);
                if (verifyFlag == 1 || verifyFlag == "1") {
                    showSuccessTips('', ele_authenticCode);
                    $("#" + ele_authenticCode).attr('verify', 'yes');
                    $("#" + ele_authenticCode + "Div").removeClass('cur');
                } else if (verifyFlag == 0 || verifyFlag == "0") {
                    showErrorTips(msg_authenticCodeError, ele_authenticCode);
                } else if (verifyFlag == 2 || verifyFlag == "2") {
                    showErrorTips(msg_authenticCodeOutOfDate, ele_authenticCode);
                } else {
                    showErrorTips(msg_authenticCodeOutOfDate, ele_authenticCode);
                }
            },
            error: function() {
                showErrorTips(msg_authenticCodeOutOfDate, ele_authenticCode);
            }
        };
        $.ajax(options);
    }
}

function verifyCodeBlur() {
    if ($("#" + ele_verifyCode + "Div").hasClass('hide')) {
        return;
    }
    //去除失去焦点class
    $("#" + ele_verifyCode).removeClass(cls_focus);
    $("#" + ele_verifyCode).attr('verify', 'false');
    var verifyCode = $.trim($('#' + ele_verifyCode).val());
    if (!verifyCode) {
        showErrorTips(msg_verifyCodeNotEmpty, ele_verifyCode);
        return;
    } else if (verifyCode.length != 6 || (!verifyCode.match('^[0-9]{1,}$'))) {
        showErrorTips(msg_verifyCodeNotError, ele_verifyCode);
        return;
    } else {
        $("#verifyCodeTips").hide();
    }
    $("#" + ele_verifyCode).attr('verify', 'yes');
}
function verifyEmailCodeBlur() {
    if ($("#" + ele_verifyCodeEmail + "Div").hasClass('hide')) {
        return;
    }
    //去除失去焦点class
    $("#" + ele_verifyCodeEmail).removeClass(cls_focus);
    $("#" + ele_verifyCodeEmail).attr('verify', 'false');
    var verifyemailCode = $.trim($('#' + ele_verifyCodeEmail).val());
    if (!verifyemailCode) {
        showErrorTips(msg_verifyEmailNotEmpty, ele_verifyCodeEmail);
        return;
    } else if (verifyemailCode.length != 6 || (!verifyemailCode.match('^[0-9]{1,}$'))) {
        showErrorTips(msg_verifyEmailCodeNotError, ele_verifyCodeEmail);
        return;
    }
    $("#verifyCodeEmailTips").html("");
    $("#verifyCodeEmailTips").hide();
    $("#" + ele_verifyCodeEmail).attr('verify', 'yes');
}
function enableConfirmPassword() {
    var password = $.trim($("#registerForm #password").val());
    var confirmPassword = $.trim($("#" + ele_confirmPassword).val());

    confirmPasswordDisabled(!confirmPassword);

    confirmPasswordDisabled(!checkPassword(password, false) && !confirmPassword);
}

//true or false
function confirmPasswordDisabled(disabled) {
    if (disabled) {
        $("#" + ele_confirmPassword).attr("disabled", true);
    } else {
        $("#" + ele_confirmPassword).removeAttr("disabled");
    }
    resetElement(ele_confirmPassword);
}

function handleFocus(ele) {
    if (ele == 'name' && $('#name').val() == '') {
        $('#name').val('');
    }
    $("#" + ele).removeClass(cls_err);
    if (!$("#" + ele).hasClass(cls_focus)) {
        $("#" + ele).addClass(cls_focus);
    }
    $("#" + ele + "Tips").show();
    showNormalTips(eval('msg_' + ele + 'Focus'), eval('ele_' + ele));

    //输入框使用跟踪代码
    var text = eval('ele_' + ele + '_text');
    omnitureForForm(text);

    $("#" + ele + "Suc").hide();
    if ($("#pageType").length > 0 && ele == 'password') {
        $("#passwordTips").hide();
    }
//	if($("#verifyCode").val() == ""){
//		$("#verifyCodeTips").hide();
//	}
//	if($("#verifyCodeEmail").val() == ""){
//		$("#verifyCodeEmailTips").hide();
//	}

//	if($("#verifyCode").val() != ""){
//		$("#verifyCodeTips").hide();
//	}
//	if($("#verifyCodeEmail").val() != ""){
//		$("#verifyCodeEmailTips").hide();
//	}

}

function nameFocus() {
    if ($('#name').val() == '') {
        $('#name').val('');
    }
    $("#name").removeClass(cls_err);
    if (!$("#name").hasClass(cls_focus)) {
        $("#name").addClass(cls_focus);
    }
    $("#nameTips").hide();

    //输入框使用跟踪代码
    var text = "用户名";
    $("#nameSuc").hide();
    $("#nameFocusbox").show();
    $("#nameFocusTips").show();
    $("#nameTips").hide();
    $("#nameSuc").hide();
    omnitureForForm(text);
}

function showErrorTips(msg, ele) {
    if (ele == 'system') {
        alert(msg);
        return;
    }
    /*if(ele == ele_name) {
     alert()
     changedName = '';
     }*/
    showTips(cls_msg_err, msg, ele);
    $("#" + ele).addClass('err');
    $("#" + ele + "Suc").remove();
}

function showNormalTips(msg, ele) {
    showTips(cls_cur, msg, ele);
}

function showSuccessTips(msg, ele) {
    var expression = "#" + ele + "Tips";
    $(expression).empty();

    expression = "#" + ele + "Div";
    //长度为1的限制去掉 del by ywf 2015-11-12
    //长度为1的限制加上 del by sxy 2015-11-19
    if ($("#" + ele + "Suc").length == 0) {
        if (ele == "authenticCode") {
            $(expression).append('<span id="' + ele + 'Suc" class="' + cls_success + ' check-icon"></span>');
        } else {
            $(expression).append('<span id="' + ele + 'Suc" class="' + cls_success + '"></span>');
        }
    }
    $("#passwordTips").hide()
    expression = "#" + ele;
    $(expression).removeClass(cls_err);
}

//cls,可能只，success,err
//msg,显示消息
//ele,可能值，用户名(name)，密码(password)，确认密码(confirmPassword)，校验码(authenticCode)
function showTips(cls, msg, ele) {
    var expression = "#" + ele + "Tips";
    resetElement(ele);


    $(expression).append('<div class="msg-cont">' + msg + '</div>');

    $(expression).addClass(cls);

    $(expression).show();
}

function resetElement(ele) {
    //reset class
    if ('authenticCode' != ele && ele != "emailVerifyCode" && ele != "mobileIllegal") {//为了防止出错，添加ele!="emailVerifyCode&& ele!="mobileIllegal"
        $("#" + ele + "Div").attr('class', eval('cls_base_' + ele));
    }
    $("#" + ele + "Tips").attr('class', cls_cur);
    //clear message
    $("#" + ele + "Tips").empty();
    $("#" + ele + "Suc").hide();
}

function isSameWord(text) {
    if (text) {
//		if(!text.match('[a-zA-Z]')) {
//			return false;
//		}
        var c = text.substr(0, 1);
        for (var i = 1; i < text.length; i++) {
            var c2 = text.substr(i, 1)
            if (c != c2) {
                return false;
            }
        }
    }

    return true
}

//2015-12-23 mod by ywf
function checkPassword(password, showMessage) {
    //(b)
    if (!password) {
        if (showMessage)
            showErrorTips(msg_passwordNotEmpty, ele_password);
        return false;
    }
    //6-20
    if (!password.match('.{6,20}')) {
        if (showMessage)
            showErrorTips(msg_passwordLength6To20, ele_password);
        return false;
    }
    //不能为同一字符
    if (isSameWord(password)) {
        if (showMessage)
            showErrorTips(msg_passwordCanntSameWord, ele_password);
        return false;
    }
    //不能全为数字
    if (password.match('^[0-9]{1,}$')) {
        if (showMessage)
            showErrorTips(msg_passwordCanntAllNumber, ele_password);
        return false;
    }

    if (!password.match('[A-Za-z0-9~!@#$%^&*()_+\\-=]+') || password.match('[A-Za-z0-9~!@#$%^&*()_+\\-=]+')[0].length < password.length) {
        if (showMessage)
            showErrorTips(msg_passwordInvalidCode, ele_password);
        return false;
    }

    //密码不能与用户名相同
    var loginName = $.trim($("#name").val());
    if (loginName == password) {
        if (showMessage)
            showErrorTips(msg_passwordCanntEqualName, ele_password);
        return false;
    }

    if (showMessage) {
        showSuccessTips('', ele_password);
        $("#passwordTips").hide()
    }
    ;
    return true;
}

function showGomexy() {
    var display = $(".newreg-xy-txt").css('display');
    if ('none' == display)
        lxf.opendiv('.newreg-xy-txt');
    else
        lxf.closediv('.newreg-xy-txt');
}
function changeActiveMethod(act, method) {
    var url = window.location.href;
    url = removeAndAddParamFromURL(url, 'act', 'm');
}
function removeAndAddParamFromURL(url, paramName, paramValue) {
    // remove '#' and after it text
    var pos = url.indexOf('#');
    if (pos > 0) {
        url = url.substr(0, pos);
    }
    var param = getParameterFromURL(url, paramName);
    url = url.replace(param, "");
    if (url.charAt(url.length - 1) != '?' && url.charAt(url.length - 1) != '&') {
        if (url.indexOf('?') > 0) {
            url = url + '&';
        } else {
            url = url + '?';
        }
    }
    url = url + paramName + "=" + paramValue;

    return url;
}
function getParameterFromURL(url, paramName) {
    var reg = new RegExp(paramName + "=(\\w*&?)");
    var result = url.match(reg);
    if (result != null) {
        return unescape(result[0]);
    } else {
        return null;
    }
}

function showPasswordMessage() {
    if ($("#password").val() == "") {
        $("#" + ele_password).attr('verify', 'false');
        showErrorTips(msg_passwordNotEmpty, ele_password);
    }
    $("#passwordTips1").html($("#passwordTips").html());
}

function moreName(event) {
    //隐藏推荐用户名
    showTJName(false);
    var sval = this.value;
    if (!sval) {
        return;
    }
    var defualtValue = '';
    if (sval.indexOf(defualtValue) > -1 && sval.length > defualtValue.length) {
        sval = sval.replace(defualtValue, '');
        $("#email").val(sval);
    }

    event = event ? event : window.event;
    var keyCode = event.keyCode;
    if (keyCode == 40 || keyCode == 38 || keyCode == 13) {
        selectName(keyCode);
    } else {
        //hide morePin
        if (sval != "") {
            var userinput = sval;
            var oldSval = "";
            var pos = sval.indexOf("@");
            if (pos >= 0) {
                oldSval = sval.substring(0, pos);
            }
            var html = "";
            if (/[\u4E00-\u9FA5]/g.test(sval) || sval.indexOf("-") > -1 || sval.indexOf("_") > -1) {
                html = "<li>" + sval + "</li>";
            } else {
                if (oldSval != '') {
                    sval = oldSval;
                }
                if (userinput.indexOf("@") == 0) {
                    sval = "";
                }
                html = "<li>" + userinput + "</li>";
                var partSurfix = initEmailSurfixArray(userinput);
                if (partSurfix != null) {
                    html = "";
                    for (var i = 0; i < partSurfix.length; i++) {
                        html += "<li>" + sval + partSurfix[i] + "</li>";
                    }
                }
            }

            if (sval.length > 25) {
                showNameList(false);
            } else {

                if (html) {
                    showNameList(true);
                    $('#name_list').html(html).find("li").mousedown(function() {
                        $("#email").val($(this).html());
                    });
                } else {
                    showNameList(false);
                    $('#name_list').removeAttr("style");
                }
            }
        } else {
            showNameList(false);
        }

    }
}

function selectName(keyCode) {//选择的name被换成了email changed by ywf 2015-11-13
    var nameListUl = $("#name_list");
    var tipindex = $("#hnseli").val() == "" ? -1 : $("#hnseli").val();
    var fobj;
    if (keyCode == 40) {
        tipindex++;
        if (tipindex == nameListUl.find("li").length) {
            tipindex = 0;
            nameListUl.find("li").eq(nameListUl.find("li").length - 1).css("background-color", "");
        }
        fobj = nameListUl.find("li").eq(tipindex);
        nameListUl.find("li").eq(tipindex - 1).css("background-color", "");
        fobj.css("background-color", "#EEEEEE");
        $("#email").val(fobj.html().replace(/<(\S*?)[^>]*>|<.*? \/>/g, ""));
        $("#schoolid").val(fobj.attr("value"));
        $("#hnseli").val(tipindex);
        return;
    }
    if (keyCode == 38) {
        tipindex--;
        if (tipindex <= -1) {
            tipindex = nameListUl.find("li").length - 1;
            nameListUl.find("li").eq(0).css("background-color", "");
        }
        nameListUl.find("li").eq(tipindex + 1).css("background-color", "");
        fobj = nameListUl.find("li").eq(tipindex);
        fobj.css("background-color", "#EEEEEE");
        if (fobj.html() != null) {
            $("#email").val(fobj.html().replace(/<(\S*?)[^>]*>|<.*? \/>/g, ""));
            $("#schoolid").val(fobj.attr("value"));
        }
        $("#hnseli").val(tipindex);
        return;
    }
    if (keyCode == 13) {
        $("#hnseli").val("-1");
        if ($("#email").val().length >= 1) {
            var combinedValue = nameListUl.find("li").eq(tipindex).html();
            if (combinedValue != null) {
                $("#email").val(combinedValue.replace(/<(\S*?)[^>]*>|<.*? \/>/g, ""));
            }
            showNameList(false);
            return;
        }
    }
}
function initEmailSurfixArray(str) {
    var pos = str.indexOf("@");
    if (pos < 0 || pos == (str.length - 1)) {
        return emailSurfixArray;
    }
    var inputSurfix = str.substring(pos, str.length);
    var suitableSurfixArray = [];
    var j = 0;
    for (var i = 0; i < emailSurfixArray.length; i++) {
        if (emailSurfixArray[i].indexOf(inputSurfix) == 0) {
            suitableSurfixArray[j] = emailSurfixArray[i];
            j++;
        }
    }
    return suitableSurfixArray;
}
/**
 * 检查用户名（手机）是否被使用
 */
var validateUserName = false;
var hasTJName = false;
function checkLoginUsable() {
    var login = $("#name").val();
    if ($.trim(login) == $.trim(changedName)) {
        if (validateUserName) {
            showErrorTips(msg_nameContainSensitiveWords, 'name');
            $("#" + ele_name).attr('verify', 'false');
            $("#" + ele_name + "Div").addClass(cls_err);
            //return;
        } else {
            showTJName(hasTJName);
            //return;
        }
        return;
    } else {

    }
    $.ajax({
        type: "POST",
        url: contextPath + "/register/commonValidateExist/" + siteVersion + ".do",
        async: false,
        data: {login: login},
        beforeSend: handleBeforeSend,
        complete: function() {
            changedName = login
        },
        success: function(data) {
            var data = $.trim(data);
            checkRefresh(data);
            //add by ywf 2015-12-24
            if (data.indexOf("validateUserName:") > -1) {
                var datas = data.split(':');
                showErrorTips(datas[1], 'name');
                $("#" + ele_name).attr('verify', 'false');
                $("#" + ele_name + "Div").addClass(cls_err);
                validateUserName = true;
                return;
            }
            validateUserName = false;
            var dataArray = data.split(':');
            var ret = dataArray[0];
            var nameList = dataArray[1].split(';');
            var option = dataArray[2];
            if (ret && ret == 'true') {
                showNameTipsWhenExists(login, nameList);
            } else {
                //不存在该用户名时
                $("#" + ele_authenticCode).attr('verify', 'yes');//校验验证码的不可少
                document.getElementById("nameTips").style.display = "none";
                showSuccessTips(msg_nameSuccess, ele_name);
                $("#" + ele_name).attr('verify', 'yes');
                $("#" + ele_name + "Div").removeClass('cur');
                $("#nameSuc").show();
            }
        },
        error: function(XMLHttpRequest, textStatus, errorThrown) {
            //showMobileCodeBox(checkMobileNumber(login));//changed by ywf 2015-11-11
            showMobileCodeBox(true);
            showSuccessTips(msg_nameSuccess, ele_name);
            $("#" + ele_name).attr('verify', 'yes');
            $("#" + ele_name + "Div").removeClass('cur');
            $("#nameSuc").show();
        }
    });
}

function showNameTipsWhenExists(login, nameList) {
    var tips = '';
    if (checkMobileNumber(login)) {
        tips = '该手机已存在，立刻<a href="javascript:void(0);" onclick="goToLogin();">登录</a>或更换手机号';
    } else {
        tips = '该用户名已存在，立刻<a href="javascript:void(0);" onclick="goToLogin();">登录</a>或更换用户名';
        if (nameList && nameList.length > 0 && nameList != '') {
            hasTJName = true;
            var html = '';
            for (var i = 0; i < nameList.length; i++) {
                var name = nameList[i];
                html += '<li><label><input type="radio" name="rename" onclick="selectMe(this);" value="' + name + '"/>' + name + '</label></li>';
            }
            $("#tj_name_list").html(html);
            showTJName(true);
        }
    }
    showErrorTips(tips, 'name');
}

function goToLogin() {
    omnitureForLink('用户名重复，登录连接');
    var login = $("#name").val();
    //var url = loginSite+'/login';
    var url = loginSite + '/login' + '.no?login=' + login;
    window.location.href = url;
}

function handleBeforeSend() {
    hasTJName = false;
    $("#" + ele_name).attr('verify', 'false');
    clearNameLayer();
    showNormalTips('检查中...', 'name');
}

/**
 * 清除（隐藏）推荐用户名、推荐邮箱
 */
function clearNameLayer() {
    //隐藏推荐用户名
    showTJName(false);
    //隐藏推荐邮箱
    showNameList(false);
}
function showTJName(display) {
    if (display) {
        $("#tj_name").removeClass().addClass("err-list");
    } else {
        $("#tj_name").removeClass().addClass("err-list hide");
    }
}
function showNameList(display) {
    if (display) {
        $('#name_list').show();
        $('#name_list').removeClass().addClass('name-list');
    } else {
        $('#name_list').removeClass().addClass('name-list hide');
    }
}
function selectMe(option) {
    $("#tj_name").removeClass().addClass("err-list hide");
    $("#name").val(option.value);
    $("#name").blur();
}
/**
 * 所有调此方法的地方，请初始化requestType，verify、send or compare
 */
function sendMobileActiveCode(mobile, requestType) {
    if (!checkMobileNumber(mobile)) {
//		showErrorTips('手机号码格式有误，请输入以13/14/15/17/18开头的11位数字。', 'mobile');
        if ($("#mobile").val() == "") {
            document.getElementById("checkMail").style.display = "none";
            document.getElementById("checkMobileSucc").style.display = "none";
            document.getElementById("checkMobileTipError2").style.display = "none";
            document.getElementById("checkMobileTipError3").style.display = "";
            document.getElementById("checkMobileTipError").style.display = "none";
            $("#checkMobileTipError3 .rule-box-text").css("color", "#c00");
        }
        return false;
    }
    //var verifyCode = $.trim($("#verifyCode").val());//changed by ywf 2015-11-11
    if (isColseRegisterCaptcha != "true") {
        //设置显示验证码时，要校验验证码
        var verifyCode = $.trim($("#authenticCode").val());
        if (verifyCode == undefined || verifyCode == "" || verifyCode.length != 4) {
            //验证码不正确，请重新输入
            showErrorTips(msg_authenticCodeError, ele_authenticCode);
            return false;
        }
    }
    var parameters = {
        mobileNumber: mobile,
        requestType: requestType,
        verifyCode: verifyCode
    };
    var options = {
        type: "POST",
        async: false,
        url: "/sms/mobileActive.no",
        data: parameters,
        success: function(data) {
            var message = $.trim(data);
            handleSendSuccess(message, mobile);
        },
        error: function() {
            alert("系统繁忙，请稍后再试!");
        }
    };
    $.ajax(options);

    omnitureForLink('发送短信验证码');
}
function handleSendSuccess(message, mobile) {
    if (message && message == 'true') {
        time_js();
    } else if (message == "COUNTLIMIT") {
        changeImageAuthenticCode('codeRefreshControlCenter');
        alert("超过次数限制，请24小时后再试");
    } else if (message == "WASBEACTIVE") {
        //将弹框的方式去掉
        alert("您输入的手机号已被激活过");
    } else if (message == "mobile-null") {
        alert("手机号码为空");
    } else if (message == "mobile-invalid") {
        alert("手机号码格式有误，请输入以13/14/15/17/18开头的11位数字。");
    } else if (message == "图片验证码已过期") {
        changeImageAuthenticCode('codeRefreshControlCenter');
        alert("图片验证码已过期");
    } else if (message == "后台校验图片验证码失败") {
        changeImageAuthenticCode('codeRefreshControlCenter');
        alert("图片验证码错误");
    } else {
        alert("发送验证码失败，请稍后再试");
    }
}

function handleActiveSuccess(message, mobile) {
    if (message && message == 'true') {
        $("#mobileDisplay").html(mobile);
        clearInterval(dt);
        showSuccessTips('', 'mobileCode');
    } else if (message && message.indexOf('您输入的手机号已被激活过') >= 0) {
        showMobileTips('err', '该手机号码已注册。您可以：1、使用其它手机号码验证2、用该手机号码<a href="' + storeSite + '/myaccount/login.jsp?login=' + mobile + '">登录</a>');
    } else if (message.indexOf('验证码错误') >= 0) {
        showErrorTips('验证码错误', 'mobileCode');
    } else if (message.indexOf('验证码过期') >= 0) {
        showErrorTips('验证码过期', 'mobileCode');
    } else if (message == "WASBEACTIVE") {
        $("#mobileErrorType").val("");
        //将弹框的方式去掉
        document.getElementById("mobileErrorType").style.display = "";
    } else {
        alert("验证失败！");
    }
    $(".tips-cx").html('');
}
var dt;
function time_js() {
    clearInterval(dt);
    $("#getVerifyCode").hide();
    $("#timeSpan").show();
    showTimeSpanMsbbox(true);
    $("#resendSpan").hide();

    var t = 60;
    this.tAtc = function() {
        t--;
        $('#time').html(t);
        if (t == 0) {
            clearInterval(dt);
            $("#getVerifyCode").hide();
            $("#timeSpan").hide();
            $("#resendSpan").show();
            showTimeSpanMsbbox(false);
            $("#time").html('60');
        }
    };
    dt = setInterval(tAtc, 1000);
}


//邮件发送的倒计时
var dtEmail;
function time_js_email() {
    clearInterval(dtEmail);
    $("#getVerifyCodeEmail").hide();
    $("#timeSpanMsbboxEmail").show();
    $("#timeSpanEmail").show();
    showTimeSpanMsbboxEmail(true);
    $("#resendSpanEmail").hide();

    var t = 90;
    this.tAtc = function() {
        t--;
        $('#timeEmail').html(t);
        if (t == 0) {
            clearInterval(dtEmail);
            $("#getVerifyCodeEmail").hide();
            $("#timeSpanMsbboxEmail").hide();
            $("#timeSpanEmail").hide();
            $("#resendSpanEmail").show();
            showTimeSpanMsbboxEmail(false);
            $("#timeEmail").html('90');
        }
    };
    dtEmail = setInterval(tAtc, 1000);
}
function showMobileCodeBox(display) {
    if (display) {
        $("#authenticCodeDiv").addClass('hide');
        $("#verifyCodeDiv").removeClass('hide');
    } else {
        $("#authenticCodeDiv").removeClass('hide');
        $("#verifyCodeDiv").addClass('hide');
    }
}
function showTimeSpanMsbbox(display) {
    $("#timeSpanMsbbox").toggle(display);
}

function showTimeSpanMsbboxEmail(display) {
    $("#timeSpanMsbboxEmail").toggle(display);
}
function clearRegInfo() {
    $("#name").val('');
    $("#password").val('');
    $("#confirmPassword").val('');
    $("#authenticCode").val('');
    $("#verifyCode").val('');
}
function changeImageAuthenticCode(contextPath, containerId) {
    function refreshOthers() {
        $(".captcha-container").each(function() {
            var currentId = $(this).attr("id");
            if (containerId == currentId) {
                return
            }
            loadImageAuthenticCode(contextPath, currentId, "display")
        })
    }
    ;
    loadImageAuthenticCode(contextPath, containerId, "generate", refreshOthers)
}
function refreshImageAuthenticCode(contextPath, containerId) {
    loadImageAuthenticCode(contextPath, containerId, "display")
}
;

function loadImageAuthenticCode(contextPath, containerId, type, callback) {
    var imageAuthenicAttr = $("#" + containerId + " .captcha-attr");
    var height = imageAuthenicAttr.attr("img-height");

    if (height != undefined) {
        path = path + "&height=" + height
    }
    ;
    var width = imageAuthenicAttr.attr("img-width");
    if (width != undefined) {
        path = path + "&width=" + width
    }
    ;
    var codeSize = imageAuthenicAttr.attr("codeSize");
    if (codeSize != undefined) {
        path = path + "&codeSize=" + codeSize
    }
    ;
    var availableTime = imageAuthenicAttr.attr("availableTime");
    if (availableTime != undefined) {
        path = path + "&availableTime=" + availableTime
    }
    ;
    var noteTitle = imageAuthenicAttr.attr("noteTitle");
    if (noteTitle != undefined) {
        path = path + "&noteTitle=" + noteTitle
    }
    ;
    path = path + "&refreshkey=" + Math.random();
    $("#" + containerId).load(path, callback)
}
/**
 * 验证邮箱地址
 * @param tager
 */
function validateEmail(tager) {
    var emailAddress = $.trim($(tager).val());
    if (emailAddress == "") {
        return true;
    }
    var reg = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,})+$/;
    if (reg.test(emailAddress)) {
        return true;
    } else {
        return false;
    }
}
//new register js,end

/**
 * 转变成校验邮箱
 * add by ywf
 */
// function changeIntoEmail(){
// 	//mobile relate
// 	document.getElementById("mobileDiv").style.display="none";
// 	document.getElementById("verifyCodeDiv").style.display="none";
// 	$("#mobile").val("");
// 	//email relate
// 	document.getElementById("emailDiv").style.display="";
// 	document.getElementById("verifyEmailCodeDiv").style.display="";

// }

/**
 * 转变成校验手机
 * add by ywf
 */
// function changeIntoMobile(){
// 	//email relate
// 	document.getElementById("emailDiv").style.display="none";
// 	document.getElementById("verifyEmailCodeDiv").style.display="none";
// 	$("#email").val("");
// 	//mobile relate
// 	document.getElementById("mobileDiv").style.display="";
// 	document.getElementById("verifyCodeDiv").style.display="";

// }

//验证手机格式是否正确以及是否存在已绑定
//function checkTelphone(){
//	var mobileNumber = $("#mobile").val();
//	// mobileNumber = mobileNumber.replace(/[ ]/g, '');
//	var regMobile=/^((1[3|8][0-9])|(14[5|7])|(15[^4,\D])|(17[0|5|6|7|8]))\d{8}$/;
//	var mobileNumber = $.trim(mobileNumber);
//	if(regMobile.test(mobileNumber)){
//		var verifyCode = $.trim($("#verifyCode").val());
//		var parameters = {
//			mobileNumber: mobileNumber,
//			requestType: "check",
//			verifyCode: "yes"
//		};
//		var options = {
//				type: "POST",
//				async:false,
//				url: "/sms/checkMobileActive.no",
//				data: parameters,
//				success: function(data) {
//					var message = $.trim(data);
//					if(message == "true"){
//						document.getElementById("checkMail").style.display="none";
//						document.getElementById("checkMobileTipError").style.display="none";
//						document.getElementById("checkMobileTipError2").style.display="none";
//						document.getElementById("checkMobileTipError3").style.display="none";
//						document.getElementById("checkMobileSucc").style.display="";
//						$("#mobile").attr('verify', 'yes');
//					}else{
//						//手机验证格式不合法或者已存在绑定时，暂不处理
//						document.getElementById("checkMail").style.display="none";
//						document.getElementById("checkMobileSucc").style.display="none";
//						document.getElementById("checkMobileTipError").style.display="none";
//						document.getElementById("checkMobileTipError3").style.display="none";
//						document.getElementById("checkMobileTipError2").style.display="";
//						$("#checkMobileTipError2 .rule-box-text").css("color","#c00");
//					}
//				},
//				error: function() {
//					alert("系统繁忙，请稍后再试!");
//				}
//		};
//		$.ajax(options);
//	}else{
//		//手机号输入不正确
//		document.getElementById("checkMail").style.display="none";
//		document.getElementById("checkMobileSucc").style.display="none";
//		document.getElementById("checkMobileTipError2").style.display="none";
//		document.getElementById("checkMobileTipError3").style.display="none";
//		document.getElementById("checkMobileTipError").style.display="";
//		$("#checkMobileTipError .rule-box-text").css("color","#c00");
//	}
//	if(mobileNumber == ""){
//		//手机号为空
//		document.getElementById("checkMail").style.display="none";
//		document.getElementById("checkMobileSucc").style.display="none";
//		document.getElementById("checkMobileTipError2").style.display="none";
//		document.getElementById("checkMobileTipError3").style.display="";
//		document.getElementById("checkMobileTipError").style.display="none";
//		$("#checkMobileTipError3 .rule-box-text").css("color","#c00");
//	}
//	
//}

//检测到非法请求，强制刷新
function checkRefresh(data) {
    if ((data) && data == 'false:非法请求') {
        location.reload();
        return;
    }
}

//验证手机格式是否正确以及是否存在已绑定
function checkTelphone() {
    var mobileNumber = $("#mobile").val();
    var regMobile = /^(13\d{9}|14\d{9}|15\d{9}|17\d{9}|18\d{9})$/;
    var mobileNumber = $.trim(mobileNumber);
    if (regMobile.test(mobileNumber)) {
        $.ajax({
            type: "POST",
            url: contextPath + "/register/validateExist/" + siteVersion + ".do",
            async: false,
            data: {login: mobileNumber},
            success: function(data) {
                var data = $.trim(data);
                checkRefresh(data);
                var dataArray = data.split(':');
                var ret = dataArray[0];
                var nameList = dataArray[1].split(';');
                var option = dataArray[2];
                //判断是否关闭邮箱注册的功能了
                if (isColseEmailRegister == "true") {
                    if (ret && ret == 'true') {
                        document.getElementById("checkMail-no").style.display = "none";
                        document.getElementById("checkMobileSucc-no").style.display = "none";
                        document.getElementById("checkMobileTipError-no").style.display = "none";
                        document.getElementById("checkMobileTipError3-no").style.display = "none";
                        document.getElementById("checkMobileTipError2-no").style.display = "";
                        $("#checkMobileTipError2-no .rule-box-text").css("color", "#c00");
                        $("#mobile").removeClass("err").addClass("err");
                        $("#mobile").attr('verify', 'no');
                    } else {
                        document.getElementById("checkMail-no").style.display = "none";
                        document.getElementById("checkMobileTipError-no").style.display = "none";
                        document.getElementById("checkMobileTipError2-no").style.display = "none";
                        document.getElementById("checkMobileTipError3-no").style.display = "none";
                        document.getElementById("checkMobileSucc-no").style.display = "";
                        $("#mobile").attr('verify', 'yes');
                    }
                } else {
                    if (ret && ret == 'true') {
                        document.getElementById("checkMail").style.display = "none";
                        document.getElementById("checkMobileSucc").style.display = "none";
                        document.getElementById("checkMobileTipError").style.display = "none";
                        document.getElementById("checkMobileTipError3").style.display = "none";
                        document.getElementById("checkMobileTipError2").style.display = "";
                        $("#checkMobileTipError2 .rule-box-text").css("color", "#c00");
                        $("#mobile").removeClass("err").addClass("err");
                        $("#mobile").attr('verify', 'no');
                    } else {
                        document.getElementById("checkMail").style.display = "none";
                        document.getElementById("checkMobileTipError").style.display = "none";
                        document.getElementById("checkMobileTipError2").style.display = "none";
                        document.getElementById("checkMobileTipError3").style.display = "none";
                        document.getElementById("checkMobileSucc").style.display = "";
                        $("#mobile").attr('verify', 'yes');
                    }

                }
            },
            error: function(XMLHttpRequest, textStatus, errorThrown) {
                alert("系统异常，稍候再试！");
            }
        });

    } else {
        //手机号输入不正确
        if (isColseEmailRegister == "true") {//是否关闭了邮箱注册的功能
            document.getElementById("checkMail-no").style.display = "none";
            document.getElementById("checkMobileSucc-no").style.display = "none";
            document.getElementById("checkMobileTipError2-no").style.display = "none";
            document.getElementById("checkMobileTipError3-no").style.display = "none";
            document.getElementById("checkMobileTipError-no").style.display = "";
            $("#checkMobileTipError-no .rule-box-text").css("color", "#c00");
            $("#mobile").removeClass("err").addClass("err");
            $("#mobile").attr('verify', 'no');
        } else {
            document.getElementById("checkMail").style.display = "none";
            document.getElementById("checkMobileSucc").style.display = "none";
            document.getElementById("checkMobileTipError2").style.display = "none";
            document.getElementById("checkMobileTipError3").style.display = "none";
            document.getElementById("checkMobileTipError").style.display = "";
            $("#checkMobileTipError .rule-box-text").css("color", "#c00");
            $("#mobile").removeClass("err").addClass("err");
            $("#mobile").attr('verify', 'no');
        }

    }
    if (mobileNumber == "") {
        //手机号为空
        if (isColseEmailRegister == "true") {//是否关闭了邮箱注册的功能
            document.getElementById("checkMail-no").style.display = "none";
            document.getElementById("checkMobileSucc-no").style.display = "none";
            document.getElementById("checkMobileTipError2-no").style.display = "none";
            document.getElementById("checkMobileTipError3-no").style.display = "";
            document.getElementById("checkMobileTipError-no").style.display = "none";
            $("#checkMobileTipError3-no .rule-box-text").css("color", "#c00");
            $("#mobile").removeClass("err").addClass("err");
            $("#mobile").attr('verify', 'no');
        } else {
            document.getElementById("checkMail").style.display = "none";
            document.getElementById("checkMobileSucc").style.display = "none";
            document.getElementById("checkMobileTipError2").style.display = "none";
            document.getElementById("checkMobileTipError3").style.display = "";
            document.getElementById("checkMobileTipError").style.display = "none";
            $("#checkMobileTipError3 .rule-box-text").css("color", "#c00");
            $("#mobile").removeClass("err").addClass("err");
            $("#mobile").attr('verify', 'no');
        }
    }

}



function emailsBlur() {
    var email = $("#email").val();
    if (email.indexOf('@') > -1 && validateEmail("#email")) {
        //校验邮箱是否被占用的情况：
        $.ajax({
            type: "POST",
            url: contextPath + "/register/validateExist/" + siteVersion + ".do",
            async: false,
            data: {login: email},
            //beforeSend: handleBeforeSend,
            //complete:function() {changedName=login},
            success: function(data) {
                var data = $.trim(data);
                checkRefresh(data);
                var dataArray = data.split(':');
                var ret = dataArray[0];
                var nameList = dataArray[1].split(';');
                var option = dataArray[2];
                //var ismobile = checkMobileNumber(login);//del by ywf 2015-11-11
                // blow code add by ywf 2015-11-11
                if (ret && ret == 'true') {
                    document.getElementById("name_list").style.display = "none";
                    //邮箱输入不正确
                    document.getElementById("checkMobile").style.display = "none";
                    document.getElementById("checkMailSucc").style.display = "none";
                    document.getElementById("emailError3").style.display = "none";
                    document.getElementById("emailError").style.display = "none";
                    document.getElementById("emailError2").style.display = "";
                    $("#emailError2 .rule-box-text").css("color", "#c00");
                    $("#email").removeClass("err").addClass("err");
                    $("#email").attr('verify', 'no');
                    return false;
                } else {
                    //不存在该用户名时
                    //验证成功
                    document.getElementById("name_list").style.display = "none";
                    document.getElementById("checkMobile").style.display = "none";
                    document.getElementById("emailError").style.display = "none";
                    document.getElementById("emailError2").style.display = "none";
                    document.getElementById("emailError3").style.display = "none";
                    document.getElementById("checkMailSucc").style.display = "";
                    $("#email").attr('verify', 'yes');
                    return true;
                }

            },
            error: function(XMLHttpRequest, textStatus, errorThrown) {
                alert("系统异常，稍候再试！");
            }
        });
    } else if (email == "") {
        document.getElementById("name_list").style.display = "none";
        //邮箱输入不正确
        document.getElementById("checkMobile").style.display = "none";
        document.getElementById("checkMailSucc").style.display = "none";
        document.getElementById("emailError").style.display = "none";
        document.getElementById("emailError2").style.display = "none";
        document.getElementById("emailError3").style.display = "";
        $("#emailError3 .rule-box-text").css("color", "#c00");
        $("#email").removeClass("err").addClass("err");
        $("#email").attr('verify', 'no');
        return false;
    } else {
        document.getElementById("name_list").style.display = "none";
        //邮箱输入不正确
        document.getElementById("checkMobile").style.display = "none";
        document.getElementById("checkMailSucc").style.display = "none";
        document.getElementById("emailError3").style.display = "none";
        document.getElementById("emailError2").style.display = "none";
        document.getElementById("emailError").style.display = "";
        $("#emailError .rule-box-text").css("color", "#c00");
        $("#email").removeClass("err").addClass("err");
        $("#email").attr('verify', 'no');
        return false;
    }

}

/**
 * [注]需要重新编写邮件发送验证码的功能
 * 所有调此方法的地方，请初始化requestType，verify、send or compare
 */
function sendEmailActiveCode(email, requestType) {
    var email = $("#email").val();
    if (email == null || email == "") {
        document.getElementById("checkMobile").style.display = "none";
        document.getElementById("checkMailSucc").style.display = "none";
        document.getElementById("emailError").style.display = "none";
        document.getElementById("emailError2").style.display = "none";
        document.getElementById("emailError3").style.display = "";
        $("#emailError3 .rule-box-text").css("color", "#c00");
        $("#email").removeClass("err").addClass("err");
        return false;
    }
    if (!(email.indexOf('@') > -1 && validateEmail("#email"))) {
        document.getElementById("checkMobile").style.display = "none";
        document.getElementById("checkMailSucc").style.display = "none";
        document.getElementById("emailError").style.display = "";
        document.getElementById("emailError2").style.display = "none";
        document.getElementById("emailError3").style.display = "none";
        $("#emailError .rule-box-text").css("color", "#c00");
        $("#email").removeClass("err").addClass("err");
        return false;
    }
    var name = $("#name").val();
    if (name == null || !nameBlur()) {
        return false;
    }

    if (isColseRegisterCaptchaEmail != "true") {
        var captcha = $.trim($("#authenticCode").val());
        if (captcha == undefined || captcha == "" || captcha.length != 4) {
            //验证码不正确，请重新输入
            showErrorTips(msg_authenticCodeError, ele_authenticCode);
            return false;
        }
    }
    var parameters = {
        name: name,
        email: email,
        requestType: requestType,
        captcha: captcha
    };
    var options = {
        type: "POST",
        async: false,
        url: "/sms/newSendVerificationEmail.no",
        dataType: 'json',
        data: parameters,
        success: function(data) {
            handleEmailSendSuc(data);
        },
        error: function() {
            alert("系统繁忙，请稍后再试!");
        }
    };
    $.ajax(options);

    omnitureForLink('发送邮箱验证码');
}

/* 处理邮件的发送结果*/
function handleEmailSendSuc(data) {
    if (data.message != null && data.message.indexOf("该邮箱已被使用，请更换邮箱!") > -1) {
        changeImageAuthenticCode('codeRefreshControlCenter');
        alert(data.message);
    }
    if (data && data.code == "3000" && data.message.indexOf("|") > -1) {
        var times = data.message.substr(data.message.indexOf("|") + 1);
        $("#sendEmailTimes").html(times);
        //邮件发送成功
        time_js_email();
    } else {
        changeImageAuthenticCode('codeRefreshControlCenter');
        alert(data.message);
    }

}


/*一分钟倒计时*/
function countdown() {
    $('#msCountdown').ready(function() {
        var currT = (new Date("2015/3/11 14:14:00")).getTime();
        var endT = (new Date("2015/3/11 14:14:59")).getTime();
        //@param {cT:当前时间(毫秒),eT:截止时间（毫秒）,gap:间隔(毫秒),aEven:到点触发的事件function,iEven:初始化函数，初始化时被调用,lEven:倒计时结束触发方法}
        $.gTimer({
            ct: currT,
            et: endT,
            aEven: function() {
                if (this.ct >= this.et) {
                    return;
                }
                var dd = Number(this.dt.format('$dd'));
                var hh = Number(this.dt.format('$hh'));
                var mm = this.dt.format('$mm');
                var ss = this.dt.format('$s');
                //console.log(Number(ss))//控制台输出语句
                //(dd>100)&& ( dd =dd%100);
                if (dd > 0) {
                    $("#hq_PhoneCode").find(".rule-box-text").html("已发送" + '<em>' + ss + '</em>' + "s");
                } else {
                    $("#hq_PhoneCode").find(".rule-box-text").html("已发送" + '<em>' + ss + '</em>' + "s");
                }
            },
            lEven: function() {//occur once end
                $("#hq_PhoneCode").find(".rule-box-text").html("重新发送");
            }
        });
    });
}
$(function() {
    if (isColseEmailRegister == "true") {
        //关闭邮箱注册服务
        document.getElementById("checkMail").style.display = "none";
    }
    if (isColseRegisterCaptcha == "true") {
        document.getElementById("authenticCodeDiv").style.display = "none";
    }
    //刷新时清空手机号和邮箱号
    $("#mobile").val("");
    $("#email").val("");
    document.getElementById('password').onkeypress = detectCapsLock;
    /*密码设置建议*/
    $(".pw-suggest").mouseover(function() {
        $("#password").attr("isClick", true);
    }).mouseleave(function() {
        $("#password").attr("isClick", false);
    });
    $(".pw-suggest").bind("click", function() {
        var _bombBox = $("#pwd-safe-box");
        _bombBox.show();
        $(".grey-layer").show();
        _bombBox.find("a").click(function() {
            _bombBox.hide();
            $(".grey-layer").hide();
        })
    });
    $("#email").focus(function() {
        $("#checkMobile").show().siblings("div").hide();
        //if($(this).val() != ""){$("#name_list").show();}
    })
    $("#mobile").focus(function() {
        if (isColseEmailRegister == "true") {
            //$("#checkMail-no").show().siblings("div").hide();
        } else {
            $("#checkMail").show().siblings("div").hide();
        }

    });
    /*电话切换成邮箱*/
    $("#phoneVerify").unbind().bind({
        "click": function() {
            if (isColseRegisterCaptchaEmail == "true") {
                $("#authenticCodeDiv").hide();//邮箱注册时，不显示验证码
            } else {
                $("#authenticCodeDiv").show();//邮箱注册时，显示验证码
            }
            var $this = $(this);
            $("#mobileDiv").hide();
            $("#mobile").val("");
            $("#checkMobileSucc").hide();
            /*短信验证码隐藏*/
            $("#verifyCodeDiv").hide();
            $("#emailDiv").show();
            $("#verifyEmailCodeDiv").show();
            $("#email").removeClass("err").removeClass("focus");
        },
        "mouseover": function() {
            $("#mobile").attr("isClick", false);
        },
        "mouseleave": function() {
            $("#mobile").attr("isClick", true);
        }

    });
    $("#phoneVerify_b").click(function() {
        if (isColseRegisterCaptchaEmail == "true") {
            $("#authenticCodeDiv").hide();//邮箱注册时，不显示验证码
        } else {
            $("#authenticCodeDiv").show();//邮箱注册时，显示验证码
        }
        var $this = $(this);
        $("#mobileDiv").hide();
        $("#mobile").val("");
        $("#checkMobileSucc").hide();
        /*短信验证码隐藏*/
        $("#verifyCodeDiv").hide();
        $("#emailDiv").show();
        $("#verifyEmailCodeDiv").show();
        $this.parents(".rule-box").hide();
        $("#checkMail").show();
        $("#email").removeClass("err").removeClass("focus");

    });
    $("#phoneVerify_c").click(function() {
        if (isColseRegisterCaptchaEmail == "true") {
            $("#authenticCodeDiv").hide();//邮箱注册时，不显示验证码
        } else {
            $("#authenticCodeDiv").show();//邮箱注册时，显示验证码
        }
        var $this = $(this);
        $("#mobileDiv").hide();
        $("#mobile").val("");
        $("#checkMobileSucc").hide();
        /*短信验证码隐藏*/
        $("#verifyCodeDiv").hide();
        $("#emailDiv").show();
        $("#verifyEmailCodeDiv").show();
        $this.parents(".rule-box").hide();
        $("#checkMail").show();
        $("#email").removeClass("err").removeClass("focus");
    });
    $("#phoneVerify_n").click(function() {
        if (isColseRegisterCaptchaEmail == "true") {
            $("#authenticCodeDiv").hide();//邮箱注册时，不显示验证码
        } else {
            $("#authenticCodeDiv").show();//邮箱注册时，显示验证码
        }
        var $this = $(this);
        $("#mobileDiv").hide();
        $("#mobile").val("");
        $("#checkMobileSucc").hide();
        /*短信验证码隐藏*/
        $("#verifyCodeDiv").hide();
        $("#emailDiv").show();
        $("#verifyEmailCodeDiv").show();
        $this.parents(".rule-box").hide();
        $("#checkMail").show();
        $("#email").removeClass("err").removeClass("focus");
    })
    /*邮箱切换成手机*/
    $("#emailVerify").unbind().bind({
        "click": function() {
            if (isColseRegisterCaptcha == "true") {
                $("#authenticCodeDiv").hide();//手机注册时，不显示显示验证码
            } else {
                $("#authenticCodeDiv").show();//手机注册时，显示验证码
            }
            var $this = $(this);
            $("#emailDiv").hide();
            $("#email").val("");
            $("#checkMailSucc").hide();
            /*短信验证码隐藏*/
            $("#verifyEmailCodeDiv").hide();
            /*显示*/
            $("#mobileDiv").show();
            $("#verifyCodeDiv").show();
            $("#mobile").removeClass("err").removeClass("focus");
        },
        "mouseover": function() {
            $("#email").attr("isClick", false);
        },
        "mouseleave": function() {
            $("#email").attr("isClick", true);
        }
    });
    $("#emailVerify_b").click(function() {
        if (isColseRegisterCaptcha == "true") {
            $("#authenticCodeDiv").hide();//手机注册时，不显示显示验证码
        } else {
            $("#authenticCodeDiv").show();//手机注册时，显示验证码
        }
        var $this = $(this);
        $("#emailDiv").hide();
        $("#email").val("");
        $("#checkMailSucc").hide();
        /*短信验证码隐藏*/
        $("#verifyEmailCodeDiv").hide();
        /*显示*/
        $("#mobileDiv").show();
        $("#verifyCodeDiv").show();
        $this.parents(".rule-box").hide();
        $("#checkMobile").show();
        $("#mobile").removeClass("err").removeClass("focus");
    });
    $("#emailVerify_c").click(function() {
        if (isColseRegisterCaptcha == "true") {
            $("#authenticCodeDiv").hide();//手机注册时，不显示显示验证码
        } else {
            $("#authenticCodeDiv").show();//手机注册时，显示验证码
        }
        var $this = $(this);
        $("#emailDiv").hide();
        $("#email").val("");
        $("#checkMailSucc").hide();
        /*短信验证码隐藏*/
        $("#verifyEmailCodeDiv").hide();
        /*显示*/
        $("#mobileDiv").show();
        $("#verifyCodeDiv").show();
        $this.parents(".rule-box").hide();
        $("#checkMobile").show();
        $("#mobile").removeClass("err").removeClass("focus");
    });
    $("#emailVerify_n").click(function() {
        if (isColseRegisterCaptcha == "true") {
            $("#authenticCodeDiv").hide();//手机注册时，不显示显示验证码
        } else {
            $("#authenticCodeDiv").show();//手机注册时，显示验证码
        }
        var $this = $(this);
        $("#emailDiv").hide();
        $("#email").val("");
        $("#checkMailSucc").hide();
        /*短信验证码隐藏*/
        $("#verifyEmailCodeDiv").hide();
        /*显示*/
        $("#mobileDiv").show();
        $("#verifyCodeDiv").show();
        $this.parents(".rule-box").hide();
        $("#checkMobile").show();
        $("#mobile").removeClass("err").removeClass("focus");
    })
    /*邮箱推送*/
    // $("#email").changeTips({
    //        divTip:".email-list"
    //    });
    /*国美在线服务协议*/
    $(".agreement-select a").click(function() {
        var _agreeSelect = $(".bomb-box-x")
        _agreeSelect.show();
        $(".grey-layer").show();
        _agreeSelect.find(".bomb-box-title a").click(function() {
            _agreeSelect.hide();
            $(".grey-layer").hide();
        })
        $("#Agreement").click(function() {
            _agreeSelect.hide();
            $(".grey-layer").hide();
            $("#checkInput").attr("checked", "checked");
            $("#serviceAgreement").hide();
        })
    });

    $("#checkInput").change(function() {
        if ($("#checkInput").prop("checked")) {
            $("#serviceAgreement").hide()
        } else {
            $("#serviceAgreement").show()
            $("#serviceAgreement").find(".rule-box-text").css("color", "#C00");
        }
    })
});

function notifyOthers(externalUrls, redirectUrl) {
    if (externalUrls && externalUrls.length > 0) {
        var completeTotal = 0;
        for (var i = 0; i < externalUrls.length; i++) {
            var url = externalUrls[i].url;
            url += url.indexOf('?') > 0 ? '&' : '?';
            url += "uuid=" + externalUrls[i].uuid;
            $.ajax({
                type: "get",
                // async:false,
                url: url,
                dataType: "jsonp",
                timeout: 1000,
                jsonp: "callbackparam",
                jsonpCallback: "success_jsonpCallback",
                complete: function(json) {
                    completeTotal++;
                    if (completeTotal == externalUrls.length) {
                        if (redirectUrl) {
                            window.location.href = redirectUrl;
                        }
                    }
                },
                success: function(data) {
                },
                error: function(data) {
                }
            });

        }
    }
}


function loginEmail() {
    var email = $("#email").val();
    if (checkEmail(email)) {
        var type = email.substr(email.indexOf("@"));
        if (type == "@189.cn") {
            window.open("http://webmail30.189.cn/w2/");
        } else if (type == "@163.com") {
            window.open("http://mail.163.com/");
        } else if (type == "@126.com") {
            window.open("http://mail.126.com/");
        } else if (type == "@qq.com") {
            window.open("http://mail.qq.com/cgi-bin/loginpage");
        } else if (type == "@sina.com") {
            window.open("http://mail.sina.com.cn/");
        } else if (type == "@gmail.com") {
            //window.open("http://www.gmail.com");
            alert("不可用的邮箱地址！");
        } else if (type == "@sohu.com") {
            window.open("http://mail.sohu.com/");
        } else if (type == "@yahoo.cn") {
            window.open("http://login.yahoo.com/");
        } else if (type == "@vip.163.com") {
            window.open("http://vip.163.com/");
        } else if (type == "@vip.126.com") {
            window.open("http://vip.163.com/");
        } else if (type == "@188.com") {
            window.open("http://www.188.com/");
        } else if (type == "@139.com") {
            window.open("http://mail.10086.cn/");
        } else if (type == "@yeah.net") {
            window.open("http://www.yeah.net/");
        } else {
            alert("不可识别的邮箱地址，请自行登录！");
        }
    } else {
        alert("邮箱不合法！");
    }
}

/**
 * 判断capsLock按键的状态
 * @param event
 */
function  detectCapsLock(event) {
    var e = event || window.event;
    var o = e.target || e.srcElement;
    // var oTip = o.nextSibling;
    // var oTip = $("#capsLocked");
    var keyCode = e.keyCode || e.which; // 按键的keyCode 
    var isShift = e.shiftKey || (keyCode == 16) || false; // shift键是否按住
    if (
            ((keyCode >= 65 && keyCode <= 90) && !isShift) // Caps Lock 打开，且没有按住shift键 
            || ((keyCode >= 97 && keyCode <= 122) && isShift)// Caps Lock 打开，且按住shift键
            ) {
//    	 oTip.style.display = '';
        // $("#capsLocked").style.display = 'none';
        $("#capsLocked").show();
    }
    else {
//    	 oTip.style.display  =  'none';
        //$("#capsLocked").style.display = 'none';
        $("#capsLocked").hide();
    }
}
$("#checkInput").change(function() {

    if ($(this).attr("isclick") == true) {
        $(this).attr("isclick", false)
    } else {
        $(this).attr("isclick", true)
    }
});

//add by ywf 2015-12-23 
function strlen(str) {
    var len = 0;
    for (var i = 0; i < str.length; i++) {
        var c = str.charCodeAt(i);
        if ((c >= 0x0001 && c <= 0x007e) || (0xff60 <= c && c <= 0xff9f)) {
            len++;
        } else {
            len += 2;
        }
    }
    return len;
}

function containSpecial(s) {
    var containSpecial = RegExp(/[(\ )(\~)(\!)(\@)(\#)(\$)(\%)(\^)(\&)(\*)(\()(\))(\+)(\=)(\[)(\])(\{)(\})(\|)(\\)(\;)(\:)(\')(\")(\,)(\.)(\/)(\<)(\>)(\?)(\)]+/);
    return (containSpecial.test(s));
}

